﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mds.DFSClient
{
  public  class DFSClient:IDFSClient
    {
      private DistributedFileProviderClient client;
      public DFSClient()
      {
          client = new DistributedFileProviderClient();
      }
        public BaseFrameModel.OperationResult<bool> SaveFile(DFSFile file)
        {
           var result= client.Save(file.KeySpace, file.Id, file.FileName, file.FileSuffix, file.FileData, file.FileExtension);
           return new BaseFrameModel.OperationResult<bool>(result.Result);
        }

        public BaseFrameModel.OperationResult<DFSFile> GetFile(string dfsPath)
        {
            var file=new DFSFile();
            file.ParseDfsPath(dfsPath);
            var result = client.GetFile(file.KeySpace, file.Id);
            if (result.Result)
            {
                file.FileData = result.Data.FileData;
                file.FileExtension = result.Data.FileExtension;
                file.FileName = result.Data.FileName;
                file.FileSize = result.Data.FileSize;
                file.FileSuffix = result.Data.FileSuffix;
                file.Id = result.Data.Id;
                file.KeySpace = result.Data.KeySpace;
            }
            return new BaseFrameModel.OperationResult<DFSFile>(file,result.Result);
        }

        public BaseFrameModel.OperationResult<bool> DeleteFile(string dfsPath)
        {
            var file=new DFSFile();
            file.ParseDfsPath(dfsPath);
           var result=client.Delete(file.KeySpace, file.Id);
           return new BaseFrameModel.OperationResult<bool>(result.Result);
        }
    }
}
